var Cesium = require('cesium/Cesium');
require('./css/main.css');
require('cesium/Widgets/widgets.css');
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzYThjMTI0OC0xOTE3LTRmNGEtYjZkNS02OWNmODNkYTA5MDEiLCJpZCI6NDQ4NjQsImlhdCI6MTYxNDUyMDg2OX0.JCjqt607bGjZFbxY4yAefUjZ1AGX0uj_M2jP5XsuAII';
var clockViewModel = new Cesium.ClockViewModel();
var options2D = {
  homeButton: false,
  fullscreenButton: false,
  sceneModePicker: false,
  clockViewModel: clockViewModel,
  infoBox: false,
  geocoder: false,
  sceneMode: Cesium.SceneMode.SCENE2D,
  timeline: false,
  navigationHelpButton: false,
  animation: false,
  clockViewModel: clockViewModel,
};
var view2D = new Cesium.Viewer("rightTop", options2D);
view2D.scene.screenSpaceCameraController.enableRotate = false;
view2D.scene.screenSpaceCameraController.enableTranslate = false;
view2D.scene.screenSpaceCameraController.enableZoom = false;
view2D.scene.screenSpaceCameraController.enableTilt = false;
view2D.scene.screenSpaceCameraController.enableLook = false;
view2D.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);

var viewer = new Cesium.Viewer("cesiumContainer", {
  infoBox: false,
  animation: false,    //左下角的动画仪表盘
  baseLayerPicker: false,  //右上角的图层选择按钮
  geocoder: false,  //搜索框
  homeButton: false,  //home按钮
  sceneModePicker: false, //模式切换按钮
  timeline: false,    //底部的时间轴
  navigationHelpButton: false,  //右上角的帮助按钮，
  fullscreenButton: false,   //右下角的全屏按钮
  clockViewModel: clockViewModel,
  // selectionIndicator: false, //去除绿框
  // terrainProvider : Cesium.createWorldTerrain({
    // requestVertexNormals: true //开启全球光照
  // })
  terrainProvider : Cesium.createWorldTerrain(),
});
viewer.scene.camera.setView({
  // 初始化相机经纬度
  destination : new Cesium.Cartesian3.fromDegrees(87.5826532878855, 43.83421984405496, 25000000),
  orientation: {
      heading : Cesium.Math.toRadians(0),
      pitch : Cesium.Math.toRadians(-90.0),//从上往下看为-90
      roll : 0
  }
});

// depthTestAgainstTerrain
// 设置该属性为true之后，标绘将位于地形的顶部；
// 如果设为false（默认值），那么标绘将位于平面上。所以被高程地形遮挡。
// 缺陷：开启该属性有可能在切换图层时会引发标绘消失的bug。
// viewer.scene.globe.depthTestAgainstTerrain = true;
viewer.scene.globe.depthTestAgainstTerrain = false;
// viewer.scene.globe.enableLighting = true;


//建筑标注
var markeringsList = [
  { lng: 87.56338084656328, lat: 43.86492822311057, text: "新疆地震局"},
  { lng: 87.56419080123291, lat: 43.863810028422925, text: "维吾尔族自治区科学技术厅" },
  { lng: 87.56590157057877, lat: 43.86377186203437, text: "自治区质监局北京路住宅区" },
  { lng: 87.56435308628883, lat: 43.86459056329426, text: "中国科学院新疆科技查新咨询中心" },
  { lng: 87.56287686743855, lat: 43.86310688442376, text: "新疆维吾尔自治区环境保护科学研究院" },
  { lng: 87.56107955874246, lat: 43.86350398385681, text: "中移铁通" },
  { lng: 87.56160670558141, lat: 43.864721027812635, text: "国家专业技术人员继续教育基地" },
  { lng: 87.56160670558141, lat: 43.864721027812635, text: "国家专业技术人员继续教育基地" },
  
  
];

//一带一路
// var buildingsList = [
//   { lng: 108.93560614042237, lat: 34.343306471991795, text: "长安" },
//   { lng: 	105.72189385966445, lat: 34.58180383610608, text: "天水" },
//   { lng: 103.8357439241842, lat: 36.05989644418678, text: "兰州" },
//   { lng: 102.63514862680844, lat: 37.92776860652805, text: "武威" },
//   { lng: 100.44994972530365, lat: 38.92403685827515, text: "张掖" },
//   { lng: 98.2880374593386, lat: 39.770508516064865 , text: "嘉峪关" },
//   { lng: 95.78483513341506, lat: 40.52088870088548, text: "安西" },
//   { lng: 94.66378435888525, lat: 40.1418118751942, text: "敦煌" },
//   { lng: 94.14487081631589, lat: 39.96547741877161, text: "阳关" },
//   { lng: 88.93484174881048, lat: 39.23377297163732, text: "米兰古城" },
//   { lng: 79.92164398452222, lat: 37.11409669383996, text: "和田" },
//   { lng: 75.9847828665305, lat: 39.467877281992415, text: "喀什" },
//   { lng: 77.245895961476, lat: 38.41514943398068, text: "莎车" },
//   { lng: 93.86414148431977, lat: 40.35334933292606, text: "玉门关" },
//   { lng: 82.95900368461373, lat: 41.71824889876045, text: "库车" },
//   { lng: 80.25549110928378, lat: 41.166150037466366, text: "阿克苏" },
//   { lng: 76.1724036070202, lat: 39.721708347414264, text: "阿图什" },
//   { lng: 81.51583777770938, lat: 43.966264383676815, text: "伊宁" },
//   { lng: 93.50733472454357, lat: 42.81870581626831, text: "哈密" },
//   { lng: 89.18439212398388, lat: 42.950070496680326, text: "吐鲁番" },
//   { lng: 84.90619886399307, lat: 44.4234443362094, text: "奎屯" },
//   { lng: 80.84642891038935, lat: 44.053875342953276, text: "霍城" },
// ]

//一带一路
var buildingsList1 = [
  { lng: 118.67766009378781, lat: 24.86418990011057, text: "泉州" },
  { lng: 113.25438830729439, lat: 23.130920519796682, text: "广州" },
  { lng: 110.1861800496309, lat: 20.04984255838639, text: "海口" },
  { lng: 109.12087542435161, lat: 21.465503188894232, text: "北海" },
  { lng: 101.67477337429615, lat: 3.1487934998089764, text: "吉隆坡" },
  { lng: 88.35004468368095, lat: 22.57270335998801, text: "加尔各答" },
  { lng: 36.81058054572774, lat: -1.2862030017160453, text: "内罗毕" },
  { lng: 23.712749457928147, lat: 37.982908711300546, text: "雅典" },
  { lng: 	12.293183365622953, lat: 45.4420411139393, text: "威尼斯" },
]
var buildingsList2 = [
  { lng: 	12.293183365622953, lat: 45.4420411139393, text: "威尼斯" },
  { lng: 4.461941427201534, lat: 51.92671102005058, text: "鹿特丹" },
  { lng: 6.744968081997575, lat: 51.43448997595164, text: "杜伊斯堡" },
  { lng: 28.961252683248382, lat: 41.00907583467424, text: "伊斯坦布尔" },
  { lng: 66.95147566470936, lat: 39.644130229011786, text: "撒马尔罕" },
  { lng: 74.56181072731385, lat: 42.87289327270496, text: "比什凯克" },
  { lng: 76.84328110286044, lat: 43.22716759964857, text: "阿拉木图" },
  { lng: 80.4198614233811, lat: 44.22708982789583, text: "霍尔果斯" },
  { lng: 87.5826532878855, lat: 43.83421984405496, text: "乌鲁木齐" },
  { lng: 103.8357439241842, lat: 36.05989644418678, text: "兰州" },
  { lng: 108.93560614042237, lat: 34.343306471991795, text: "西安" },
]

//0: 展厅 1-~: 直播点
var list = [
  { lng: 87.56280760277768, lat: 43.86387580483447, type: "model", text: "二楼展厅", src: './images/zt.jpg' },
  { lng: 87.60138285675833, lat: 43.80285036094045, type: "videoPoint1", text: "asdfasdf", src: './images/zb.jpg' }
];
var limit = 0.02;

var imageHeight = 10;
var labelHeight = 10;

addPointAndView(list);
view2D._cesiumWidget._creditContainer.style.display="none"//取消版权信息

function addPointAndView(list) {
  var minLat = 180, minLng = 180, maxLat = -180, maxLng = -180;
  for (var i = 0; i < list.length; i++) {
    var obj = list[i];
    if (obj.lat > maxLat) maxLat = obj.lat;
    if (obj.lng > maxLng) maxLng = obj.lng;
    if (obj.lat < minLat) minLat = obj.lat;
    if (obj.lng < minLng) minLng = obj.lng;
    view2D.entities.add({
      properties: { type: obj.type },
      position: Cesium.Cartesian3.fromDegrees(obj.lng, obj.lat),
      point: {
        pixelSize: 16,
        color: Cesium.Color.YELLOW,
      },
    });
  }
  view2D.scene.camera.setView({
    destination: Cesium.Rectangle.fromDegrees(minLng - limit, minLat - limit, maxLng + limit, maxLat + limit),
    orientation: {
      heading: Cesium.Math.toRadians(-106),
      pitch: 0,
      roll: 0
    }
  })
  var origin = list[0];
  for (var i = 1; i < list.length; i++) {
    var target = list[1];
    view2D.entities.add({
      name: "Glowing blue line on the surface",
      polyline: {
        positions: Cesium.Cartesian3.fromDegreesArray([origin.lng, origin.lat, target.lng, target.lat]),
        width: 3,
        material: new Cesium.PolylineGlowMaterialProperty({
          glowPower: 0.2,
          taperPower: 0.5,
          color: Cesium.Color.CORNFLOWERBLUE,
        }),
      },
    });
  }
  
  var handler = new Cesium.ScreenSpaceEventHandler(view2D.scene.canvas);
  handler.setInputAction(function (movement) {
    var pickedFeature = view2D.scene.pick(movement.position);
    if (pickedFeature) {
      var value = pickedFeature.id.properties.type._value;
      for (var i = 0; i < list.length; i++) {
        if (value == list[i].type) return viewer.flyTo(list[i].entity);
      }
    }
  }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}

function createModel(url, height) {
  viewer.entities.removeAll();

  var position = Cesium.Cartesian3.fromDegrees(
    list[0].lng, list[0].lat,
    // height
    702
  );
  var heading = Cesium.Math.toRadians(-106);
  var pitch = 0;
  var roll = -0.05;
  var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
  var orientation = Cesium.Transforms.headingPitchRollQuaternion(
    position,
    hpr
  );
  
  //展厅
  var entity = list[0].entity= viewer.entities.add({
    properties: { type: list[0].type },
    name: url,
    position: position,
    orientation: orientation,
    model: {
      uri: url,
      scale: 0.0012,
      // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND //贴地
    },
  });
  //展厅图标
  viewer.entities.add({
    position: Cesium.Cartesian3.fromDegrees(
      list[0].lng, list[0].lat,
      imageHeight
    ),
    properties: { type: 'modelImg' },
    id: 'modelImg',
    //添加图标
    billboard : { //图标
      image  : list[0].src,
      width : 40,
      height : 40,
      pixelOffset : new Cesium.Cartesian2( 0, -30 ),   //偏移量
      heightReference: Cesium.HeightReference.CLAMP_TO_GROUND //贴地
    }
  });
  // 展厅文字
  viewer.entities.add({
    properties: { type: 'modelText' }, //加上properties防止报错
    id: 'modelText',
    position: Cesium.Cartesian3.fromDegrees(
      list[0].lng, list[0].lat,
      labelHeight
    ),
    label: {
      text: list[0].text,
      font: "8px sans-serif",
      // scaleByDistance: new Cesium.NearFarScalar(1.5e2, 2.0, 1.5e7, 1),
      pixelOffset : new Cesium.Cartesian2( 0, -60 ),   //偏移量
      heightReference: Cesium.HeightReference.CLAMP_TO_GROUND //贴地
    },
  });

  //三个外部慢直播所在的地理信息位置
  for (var i = 1; i < list.length; i++) {
    var obj = list[i];
    obj.entity = viewer.entities.add({
      //只点击图标跳转到内部 与label img分开
      properties: { type: obj.type }, 
      id: 'videoPointImg' + i,
      position: Cesium.Cartesian3.fromDegrees(
        obj.lng, obj.lat, 
        imageHeight
      ),
      //添加图标
      billboard : { //图标
        image  : obj.src,
        width : 40,
        height : 40,
        pixelOffset : new Cesium.Cartesian2( 0, -30 ),   //偏移量
        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND //贴地
      }
    });
    if (obj.text) {
      viewer.entities.add({
        properties: { type: 'text' + i}, //加上properties防止报错
        id: 'videoPointText' + i,
        position: Cesium.Cartesian3.fromDegrees(
          obj.lng, obj.lat,
          labelHeight
        ),
        label: {
          text: obj.text,
          font: "8px sans-serif",
          pixelOffset : new Cesium.Cartesian2( 0, -60 ),   //偏移量
          heightReference: Cesium.HeightReference.CLAMP_TO_GROUND //贴地
        },
      });
    }
  }

  //一带一路城市
  buildings();

  //建筑标注
  markerings();

  //轨迹路线
  var lineArr1 = [{"lng":118.73621995923412,"lat":24.379844662875826,"height":-5733.495307484788},{"lng":118.03282778971396,"lat":22.625297440968993,"height":-586.3348549920066},{"lng":117.28983158798009,"lat":21.771507873825435,"height":-2845.436702452755},{"lng":116.42161770659436,"lat":21.309358202269806,"height":-3453.196804302815},{"lng":115.58545761305027,"lat":21.275475243313757,"height":-2460.845540368882},{"lng":114.38984230484411,"lat":21.5807811412004,"height":-3146.0847870917282},{"lng":113.48298264457985,"lat":22.355610690594006,"height":-1875.689821069444},{"lng":114.27828965213457,"lat":21.598210122956438,"height":-3209.5627295372547},{"lng":115.06037890799891,"lat":21.386026925718006,"height":-2368.1272166524536},{"lng":114.2212518581473,"lat":20.01913309467926,"height":-2390.781110676571},{"lng":111.80526491317656,"lat":17.585997300118454,"height":-2719.4067906426926},{"lng":110.08689062781086,"lat":16.979320060411133,"height":-6877.234810195949},{"lng":108.90816975408194,"lat":17.449968286887483,"height":-6257.287209497011},{"lng":108.23993917887854,"lat":18.000710807784195,"height":-4146.1321482751855},{"lng":107.530924353165,"lat":18.63831626317735,"height":-4961.829713247019},{"lng":108.1991403170926,"lat":19.772910415072435,"height":-4591.712069511239},{"lng":109.53658634672387,"lat":19.985966870187394,"height":-1072.2295982973674},{"lng":108.1360433352227,"lat":19.745646739594836,"height":-4685.906660731903},{"lng":108.68460213626797,"lat":20.81416935952365,"height":-3775.3308873463893},{"lng":108.25836409655047,"lat":19.926590214859285,"height":-4547.882266460732},{"lng":107.71035811887603,"lat":18.909033145082446,"height":-5073.606293747134},{"lng":107.35529474174146,"lat":18.673465462555342,"height":-5065.4042531845635},{"lng":108.07977266439028,"lat":18.23166706049716,"height":-3794.1300220036715},{"lng":108.92784529914519,"lat":17.48008274104801,"height":-6256.200629165685},{"lng":110.07993657541002,"lat":14.447674837525362,"height":-1765.597415648616},{"lng":109.79893212255702,"lat":11.111812016857753,"height":-4708.718079304332},{"lng":108.5050967854604,"lat":9.022370964820123,"height":-4638.804176402782},{"lng":104.69956388625322,"lat":0.31878060004661063,"height":-1960.448160893308},{"lng":101.75263561782144,"lat":2.008671376295776,"height":-2705.5856955600025},{"lng":99.81535114755653,"lat":4.251367947925059,"height":-4235.493952774054},{"lng":88.77633877749628,"lat":21.652722171224916,"height":-4126.956958999469},{"lng":81.66176436647969,"lat":4.564946403185549,"height":-4921.5918776144},{"lng":41.94494301315302,"lat":-2.6168260378375447,"height":-15077.2943995173},{"lng":50.99216923475824,"lat":7.1296552001832785,"height":-5719.7363569409345},{"lng":52.09181076511306,"lat":13.23568590151601,"height":-4352.924265387592},{"lng":44.55952096901735,"lat":11.40727294828204,"height":-2820.0761481873496},{"lng":35.938557068035486,"lat":25.196386879667454,"height":-2464.2194683649022},{"lng":33.19350462336641,"lat":28.395034045952503,"height":-1918.4683786101227},{"lng":32.62473223936814,"lat":29.45592374990744,"height":-2483.145040083277},{"lng":31.962573694515473,"lat":31.843841585660076,"height":-3156.2153198338833},{"lng":24.123689735248853,"lat":37.66005515129002,"height":-2551.1309320068726},{"lng":23.61201461629546,"lat":35.885739246681524,"height":-3203.2462377524344},{"lng":22.339971010193498,"lat":35.795021866390485,"height":-3305.9884626465782},{"lng":19.66527054683522,"lat":38.87844879406134,"height":-4540.969026345231},{"lng":18.056520488980492,"lat":41.346911150901505,"height":-3818.5141929116353},{"lng":12.686415301857268,"lat":45.196077674309066,"height":-2902.0023203469013},{"lng":12.376322036356486,"lat":45.36828830846537,"height":-861.6279511319883},{"lng":12.439433814795331,"lat":45.36162044454738,"height":-879.3961060103535}]
  var lineArr2 = [{"lng":12.030398917327082,"lat":45.66120356823115,"height":-2056.3009879734823},{"lng":10.714763937148282,"lat":46.48519494809765,"height":1434.042485809411},{"lng":9.107236697435967,"lat":47.23761611449079,"height":506.59450608302336},{"lng":8.03972536344348,"lat":48.12790760917529,"height":-2360.7916858452404},{"lng":7.433125416537012,"lat":48.780963514855706,"height":-3321.3741350922073},{"lng":6.371923567801062,"lat":49.31286649884198,"height":-2738.264480880381},{"lng":5.113087219104791,"lat":50.00488890269764,"height":-1754.4183762544308},{"lng":4.5865965524598895,"lat":50.86731462914971,"height":-2243.1972172877186},{"lng":4.321956648782655,"lat":51.6804906690323,"height":-4445.084047935948},{"lng":6.561719226230821,"lat":51.42950846517495,"height":-2250.414304727666},{"lng":10.054114215901057,"lat":51.05796304571767,"height":-2088.462676163581},{"lng":13.836413734189025,"lat":51.11205969794373,"height":-3572.1334556902884},{"lng":16.688115214452917,"lat":49.982239340204124,"height":-2386.8654733740836},{"lng":18.46856646637836,"lat":48.813026035956526,"height":-3595.4520483389774},{"lng":19.465247098220622,"lat":47.71635063226304,"height":-3354.1137446618827},{"lng":21.7326269286194,"lat":45.60427676702245,"height":-2341.5378727150155},{"lng":23.25202777950086,"lat":44.1057504465162,"height":-352.45629524139815},{"lng":24.654075308347743,"lat":42.85399591100641,"height":1215.0520282422733},{"lng":25.687256526157995,"lat":42.0060461344644,"height":-2907.4153820339575},{"lng":26.73990049756575,"lat":41.51343988274703,"height":-5229.06544432062},{"lng":28.852394907296954,"lat":41.04323173018806,"height":-5057.075179798998},{"lng":31.42949934032835,"lat":39.9968851643269,"height":-4131.434533499668},{"lng":33.88147728419944,"lat":39.57621719287313,"height":565.7016422126502},{"lng":40.28845294198673,"lat":39.17989325912472,"height":-1391.8546094424946},{"lng":43.2063580725208,"lat":39.01914574594897,"height":-3362.3955426331313},{"lng":44.29940999544773,"lat":38.62674469690306,"height":-1804.4568719892227},{"lng":45.59864618441124,"lat":37.957227478101196,"height":-513.5012819357092},{"lng":46.65361187833934,"lat":37.341483517316654,"height":-176.80226540252195},{"lng":48.00735884842889,"lat":36.30758314682413,"height":-1803.5334308212123},{"lng":49.77427266270966,"lat":35.177415296621206,"height":-2492.2108126300304},{"lng":50.965662721963184,"lat":34.594718816182535,"height":978.00516666902},{"lng":52.81343331588112,"lat":34.465738859944025,"height":-930.590047815546},{"lng":54.457567878820484,"lat":34.99098007590772,"height":-1267.238079673478},{"lng":56.35493826093113,"lat":35.907446185432796,"height":-1554.0788323354523},{"lng":58.55499543647975,"lat":36.667377014338605,"height":186.40096618313441},{"lng":60.540137346848134,"lat":37.57814567122533,"height":-2682.622377023817},{"lng":63.60064188248201,"lat":38.53986905336891,"height":-3689.9737342388885},{"lng":66.80837676600926,"lat":39.64540413801856,"height":-423.1301035206228},{"lng":70.33058468592692,"lat":41.01049212727254,"height":-566.0679561187588},{"lng":71.48659364059867,"lat":41.66898967587923,"height":1969.1453994250114},{"lng":72.41657827310253,"lat":42.1198075729451,"height":1622.7790682599968},{"lng":72.99597042713617,"lat":42.257531887520145,"height":1843.0758272526834},{"lng":74.29752682160287,"lat":42.8519942992273,"height":2759.7212585639368},{"lng":75.40961652938262,"lat":43.01152522722398,"height":1820.0481052183848},{"lng":76.15295146512281,"lat":43.110469866724834,"height":792.7783180914726},{"lng":76.85560604282931,"lat":43.22075400099624,"height":243.91329105496467},{"lng":78.08556780708005,"lat":43.46803743263573,"height":458.2268957360212},{"lng":78.67417254180009,"lat":43.670339539437215,"height":1034.6474664546956},{"lng":79.34544575729123,"lat":43.88020639435656,"height":2004.0024595516322},{"lng":79.75491578429947,"lat":44.012133350507774,"height":2626.512445455449},{"lng":80.3130802926298,"lat":44.18277575611135,"height":2817.0695836140426},{"lng":82.90414006718495,"lat":44.26541282022019,"height":-364.6389623782782},{"lng":84.00565181850178,"lat":44.08663759897097,"height":173.4821262621023},{"lng":84.91874972718357,"lat":44.01873652674629,"height":3562.9563376413835},{"lng":85.86750375504954,"lat":43.9812775770185,"height":2760.819295741557},{"lng":86.66820341716748,"lat":43.88992245368503,"height":2938.387753380877},{"lng":87.51034017473188,"lat":43.84456208493031,"height":3631.352097116216},{"lng":92.04766952379396,"lat":42.05324696330728,"height":-2029.7625073939619},{"lng":93.31420742809671,"lat":40.99778702403573,"height":-2302.0616715798105},{"lng":94.29827801955935,"lat":40.340856782618204,"height":-1090.4545445446226},{"lng":95.94367950221331,"lat":39.709116819308136,"height":2289.746959399637},{"lng":97.4468997991523,"lat":39.02373515303254,"height":-1488.2322311222556},{"lng":99.81090369223098,"lat":38.233516479198585,"height":-2163.815780946599},{"lng":101.47950339319074,"lat":37.16479808160212,"height":-4839.621374583833},{"lng":102.97067545202322,"lat":36.287997979954405,"height":-1812.3815575338897},{"lng":103.86864998324086,"lat":36.01211337578631,"height":-100.96737397991647},{"lng":105.40024282750119,"lat":35.450333790190925,"height":-1953.093136367761},{"lng":106.74033584520042,"lat":34.891916038598175,"height":-3388.391716887163},{"lng":108.97514289790945,"lat":34.30826112301749,"height":-3862.1468708290117},{"lng":109.04208183978024,"lat":34.183995719658945,"height":-3945.8426840428147}]
  drawLine(lineArr1, 'lineArr1', 1);
  drawLine(lineArr2, 'lineArr2', 2);

  viewer.flyTo(entity);
}

function buildings() {
  var buildingsList = buildingsList1.concat(buildingsList2);
  for (var i = 0; i < buildingsList.length; i++) {
    var obj = buildingsList[i];
    obj.entity = viewer.entities.add({
      properties: { type: 'buildings' + i }, //加上properties防止报错
      id: 'buildings' + i,
      position: Cesium.Cartesian3.fromDegrees(
        obj.lng, obj.lat,
        labelHeight,
      ),
      point: {
        pixelSize: 12,
        color: Cesium.Color.RED,
        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, //贴地
        // 边框颜色
        outlineColor: Cesium.Color.fromCssColorString('#fff'),
        // 边框宽度(像素)
        outlineWidth: 2,
        // 是否显示
        show: true
      },
      label: {
        text: obj.text,
        font: "10px sans-serif",
        pixelOffset : new Cesium.Cartesian2( 0, -30 ),   //偏移量
        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND //贴地
      },
    });
  }
}

function markerings() {
  for (var i = 0; i < markeringsList.length; i++) {
    var obj = markeringsList[i];
    obj.entity = viewer.entities.add({
      properties: { type: 'markerings' + i }, //加上properties防止报错
      id: 'markerings' + i,
      position: Cesium.Cartesian3.fromDegrees(
        obj.lng, obj.lat,
        labelHeight
      ),
      label: {
        text: obj.text,
        font: "8px sans-serif",
        // pixelOffset : new Cesium.Cartesian2( 0, -30 ),   //偏移量
        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND //贴地
      },
    });
  }
}

function drawLine(lineArr, name, color) {
    var cartesianLineArr = [];
    lineArr.forEach(function(list, index) {
        cartesianLineArr.push(list.lng);
        cartesianLineArr.push(list.lat);
        cartesianLineArr.push(list.height);
    })
    var line = viewer.entities.add({
        name: name,
        id: name,
        polyline: {
            positions: Cesium.Cartesian3.fromDegreesArrayHeights(cartesianLineArr),
            width: 3,
            material : new Cesium.PolylineOutlineMaterialProperty({
                glowPower : 0.6,
                color : color == 1 ? Cesium.Color.SKYBLUE : Cesium.Color.ORANGE,
                // outlineWidth : 2,
                // outlineColor : Cesium.Color.BLACK
            }),
            clampToGround: true,
        }
    })
}

//左键点击
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function (movement) {
  var pickedFeature = viewer.scene.pick(movement.position);
  if (pickedFeature) {
    var value = pickedFeature.id.properties.type._value;
    if (value === "videoPoint1") {
      window.open("https://www.jiyi2.com/wp-content/plugins/vr_manage/vr_video.php?id=61", "_blank");
    }
    if (value === "modelImg") {
      window.open("https://www.baidu.com", "_blank");
    }
  }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);



//获取当前相机高度
viewer.scene.camera.moveEnd.addEventListener(function(){
  var height = Math.ceil(viewer.camera.positionCartographic.height);
  var markeringsListArr = [];
  for(var i = 0; i < markeringsList.length; i++) {
    markeringsListArr.push(viewer.entities.getById('markerings' + i));
  }

  var modelImg = viewer.entities.getById('modelImg');
  var modelText = viewer.entities.getById('modelText');
  var lineArr1 = viewer.entities.getById('lineArr1');
  var lineArr2 = viewer.entities.getById('lineArr2');

  var videoPointImgArr = [], videoPointTextArr = [];
  for(var i = 1; i < list.length; i++) {
    videoPointImgArr.push(viewer.entities.getById('videoPointImg' + i));
    videoPointTextArr.push(viewer.entities.getById('videoPointText' + i));
  }
  console.log(height)
  if (height < 1500) {
    markeringsListArr.forEach(function(list, index) {
      list._show = true;
    })
  }
  else {
    markeringsListArr.forEach(function(list, index) {
      list._show = false;
    })
  }
  
  if(height < 100000) {
      videoPointImgArr.forEach(function(list, index) {
        list._show = true;
      })
      videoPointTextArr.forEach(function(list, index) {
        list._show = true;
      })
      modelImg._show = true;
      modelText._show = true;
      lineArr1._show =  false;
      lineArr2._show =  false;
  }else {
      videoPointImgArr.forEach(function(list, index) {
        list._show = false;
      })
      videoPointTextArr.forEach(function(list, index) {
        list._show = false;
      })
      modelImg._show = false;
      modelText._show = false;
      lineArr1._show =  true;
      lineArr2._show =  true;
  }
})

createModel(
  "../SampleData/zt.gltf",
  0
);